package com.ddl.kafka.config.topic;

import com.ddl.kafka.config.MessageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TopicProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${amqp.topicExchange}")
    private String exchange;

    public void syncSend(Integer id, String routingKey) {
        // 创建消息
        MessageData md = new MessageData();
        md.setMsg("topic");
        // 同步发送消息
        rabbitTemplate.convertAndSend(exchange, routingKey, md);
        log.info("[topic消息][发送编号：[{}] 发送成功]", id);
    }
}
